package cn.tedu.micro.demo.common.controller;

import cn.tedu.micro.demo.common.pojo.vo.CartVO;
import cn.tedu.micro.demo.common.protocol.JsonResult;
import cn.tedu.micro.demo.common.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//专门负责 购物车相关业务模块接口
@RestController
@RequestMapping("/cart/")
public class CartController {
    @Autowired
    private CartService cartService;
    @PostMapping("add")
    public JsonResult<Boolean> saveCart(
            Integer userId,
            String productCode,
            Integer count
    ){
//        demo案例，轻业务，重技术 所以业务逻辑很简陋
        cartService.saveCart(userId,productCode,count);
        return JsonResult.ok("ok",true);
    }
    @GetMapping("list")
    public JsonResult<List<CartVO>> myCartList(Integer userId){
        List<CartVO> list = cartService.myCartList(userId);
        return JsonResult.ok("ok",list);
    }
    @PostMapping("delete")
    public JsonResult<Void> deleteCart(@RequestParam("productCode") String productCode, @RequestParam("userId") Integer userId){
        cartService.deleteCart(productCode,userId);
        return JsonResult.ok("ok",null);
    }

}
